package com.tsd.core.constants;

import com.alibaba.fastjson.TypeReference;
import com.google.gson.reflect.TypeToken;
import com.tsd.core.excel.export.ExcelExportHelper;
import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.HttpResult;

import java.lang.reflect.Type;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 公共常量
 *
 * @author Hillpool
 */
public class Constants {
    /**
     * 常量值，操作-增加（1）
     */
    public static final int OP_ADD = 1;
    /**
     * 常量值，操作-减少（-1）
     */
    public static final int OP_SUB = -1;
    /**
     * 常量值，是（1）
     */
    public static final int VALUE_YES = 1;
    /**
     * 常量值，否（0）
     */
    public static final int VALUE_NO = 0;
    /**
     * 常量值，上架（1）
     */
    public static final int VALUE_ON = 1;
    /**
     * 常量值，下架（0）
     */
    public static final int VALUE_OFF = 0;
    /**
     * 根目录的父级sid
     */
    public static final String ROOT_PARENT_SID = "-1";

    public static final String KEY_NO_PAGE = "nopage";
    public static final String KEY_PAGE_NO = "pageNo";
    public static final String KEY_PAGE_SIZE = "pageSize";
    public static final String KEY_TOTAL_ROWS = "totalRows";
    public static final String KEY_SKIP_ADMIN ="skip_admin";
    /**
     * 字符串常量值，成功
     */
    public static final String VALUE_SUCCESS = "success";

    /**
     * 字符串常量值，失败
     */
    public static final String VALUE_FAIL = "fail";
    /**
     * 记录增加类型：单个增加、批量增加、导入增加、api调用增加
     * 其他业务功能特殊的增加类型自主扩展
     */
    public final static String ADD_TYPE_SINGLE = "single";
    public final static String ADD_TYPE_BAT = "bat";
    public final static String ADD_TYPE_IMPORT = "imp";
    public final static String ADD_TYPE_API = "api";

    public static final String HEADER_NAME_ACCOUNT_SET_SID = "account_set_sid";
    /**
     * 主账号sid
     */
    public static final String MASTER_USER_SID = "admin";

    public static final String LOGGER_NAME_QUARTZ = "quartzLogger";
    public static final String REQ_ATTRIBUTE_NAME_PARAMS = "params";

    public static final String REQ_ATTRIBUTE_NAME_PERMISSION_PARAMS = "permission_params";
    public static final String REQ_ATTRIBUTE_NAME_CLAIMS = "claims";
    public static final String REQ_HEADER_NAME_DEVICE_TYPE = "tmn";
    public static final String REQ_HEADER_NAME_TOKEN = "token";
    public static final String REQ_HEADER_NAME_APPLICATION = "application";
    public static final String REQ_HEADER_NAME_REFRESH_TOKEN = "refresh_token";
    /**
     * 参数中的key名称
     * 部门权限（group_permission：group_sid列表）
     * 创建者（creator_sid）
     */
    public static final String PARAMS_KEY_NAME_GROUP_PERMISSION = "group_permission";
    public static final String PARAMS_KEY_NAME_GROUP_APPLICATION = "permission_application";
    public static final String PARAMS_KEY_NAME_CREATOR_SID = "creator_sid";
    public static final String PARAMS_KEY_NAME_GROUP_LIST = "group_list";


    public static final String TABLE_NAME_SYS_ACCOUNT_SET = "sys_account_set";
    public static final String TABLE_NAME_FLYWAY_SCHEMA_HISTORY = "flyway_schema_history";
    public static final String TABLE_NAME_SYS_LOG_INFO = "sys_log_info";
    /**
     * 逗号替换正则表达式，包括空格、顿号、点号、单引号、竖线、分号登录
     */
    public static String COMMA_REPLACE_REGEX = "[ ，,、|;；‘'\\.]";
    /**
     * 日志数据库后缀
     */
    public static final String DATABASE_SUFFIX_FOR_LOG = "_log";

    /**
     * mysql的自动创建数据库
     */
    public static final String MYSQL_CREATE_DATABASE_IF_NOT_EXIST = "&createDatabaseIfNotExist=true";

    public static final String MYSQL_DB_URL_TEMPLATE = "jdbc:mysql://@host@:@port@/@catalog@?useUnicode=true&useSSL=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&allowMultiQueries=true";
    /**
     * 账套的状态，-2-过期、-1-数据库创建失败，0-数据库未创建、1-数据库创建中，2-数据库已建立
     */
    public static final int STATE_EXPIRED = -2;
    public static final int STATE_DB_CREATED_FAIL = -1;
    public static final int STATE_DB_NOT_CREATED = 0;
    public static final int STATE_DB_CREATING = 1;
    public static final int STATE_DB_CREATED = 2;
    /**
     * 用户状态：有效
     */
    public final static int USER_STATUS_VALID = 1;
    /**
     * 用户状态：无效
     */
    public final static int USER_STATUS_UNVALID = -1;
    /**
     * 删除标识，0-表示没删除
     */
    public final static int DR_VALID = 0;
    /**
     * 删除标识，1-表示已删除
     */
    public final static int DR_UNVALID = 1;

    public static final Integer VERSION_INIT = 1;

    public static final String PARAMETER_KEY_METER_TYPE = "meter_type";

    public static final String PARAMETER_KEY_METER_KIND = "meter_kind";

    public static final String CLASS_PATH_XLSX = "classpath:xlsx/";
    public static final String CLASS_PATH_EXCEL_TEMPLATE = "classpath:excelTemplate/";
    public static final String CLASS_PATH_IMPORT = "classpath:import/";
    public static final String CLASS_PATH_TEMPLATES = "classpath:templates/";

    public static final String VALUE_1 = "1";
    public static final String VALUE_PERCENTAGE = "%";
    public static final String FILE_SEPARATOR = "/";
    public static final String CONTENT_TYPE_VALUE_JSON = "text/json;charset=UTF-8";
    public static final String CONTENT_TYPE_VALUE_APPLICATION_JSON = "application/json";
    public static final String NONE_DONE_EXCEPTION_LOGGER = "noneDoneExceptionLogger";
    public static final String MODE_TSD = "tsd";

    public static final String PARENT_SID_ROOT = "root";

    public static final TypeReference<LinkedHashMap<String, String>> LINKED_HASH_MAP_STRING_STRING_TYPE_REFERENCE = new TypeReference<LinkedHashMap<String, String>>() {
    };
    public static final TypeReference<List<Map<String, Object>>> LIST_MAP_STRING_OBJECT_TYPE_REFERENCE = new TypeReference<List<Map<String, Object>>>() {
    };
    public static final Type LINKED_HASH_MAP_STRING_OBJECT_TYPE_TOKEN = new TypeToken<LinkedHashMap<String, Object>>() {
    }.getType();
    public static final Type LINKED_HASH_MAP_STRING_STRING_TYPE_TOKEN = new TypeToken<LinkedHashMap<String, String>>() {
    }.getType();
    public static final TypeReference<HttpResult<Object>> RESULT_OBJECT_TYPE_REFERENCE = new TypeReference<HttpResult<Object>>() {
    };

    public static String getExcelXlsxDateName() {
        return "Excel-" + HlpUtils.date2String(new Date(), HlpUtils.Format_Yyyy_MM_dd) + "." + ExcelExportHelper.ExcelType.XLSX.getType();
    }
}
